package com.example.demo.controller;

import com.example.demo.entity.Admin;
import com.example.demo.entity.User;
import com.example.demo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
@RequestMapping("/admin")
public class AdminController {
    AdminService adminService;
    @Autowired
    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }



    @GetMapping("/login")
    public String login(String adminName, String adminPasswrod,String verifyCode,
                        HttpSession session) throws IOException {
        System.out.println(adminName+" "+adminPasswrod);
        String kaptchaCode = session.getAttribute("verifyCode") + "";
        if (kaptchaCode.equals("null") || !verifyCode.equals(kaptchaCode)) {
            return  "验证码错误";
        }
        Admin admin = adminService.login(adminName, adminPasswrod);
        if (admin == null) {
            return "用户名或密码错误";
        } else {
            return "ok";
        }
    }
}
